package nowCoder;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * @Auther: zzx
 * @Date: 2024.03.24/3/23
 */
public class HJ88 {
    // 12 14 45 36 64 55 44
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String next = sc.nextLine();
        String[] str = next.split("-");
        String[] a = type(str[0]);
        String[] b = type(str[1]);
        int aa = Integer.parseInt(a[0]);
        int bb = Integer.parseInt(b[0]);
        if (aa > 4 && aa > bb){
            System.out.println(str[0]);
        }else if(bb > 4 && bb > aa){
            System.out.println(str[1]);
        }else if(aa == bb){
            System.out.println(ll.get(a[1]).compareTo(ll.get(b[1])) > 0 ? str[0] : str[1]);
        }else {
            System.out.println("ERROR");
        }
    }
    public static String[] type(String str){
        String[] s = str.split(" ");
        String[] xx = new String[]{"1",s[0]};
        int kin = 0;
        Map<String, Integer> l = new HashMap<>();
        for (String m : s) {
            l.put(m, l.get(m) == null ? 1 : l.get(m) + 1);
            if ("joker".equals(m) || "JOKER".equals(m)) {
                kin++;
            }
        }
        if (kin == 2){
            xx[0] = "6";
            return xx;
        }
        for (Map.Entry<String, Integer> entry : l.entrySet()) {
            if (entry.getValue() < 4){
                if (entry.getValue() > Integer.parseInt(xx[0])){
                    xx[0] = String.valueOf(entry.getValue());
                    xx[1] = entry.getKey();
                }else if (entry.getValue() == Integer.parseInt(xx[0]))
                    xx[1] = entry.getKey().compareTo(xx[1]) > 0 ? entry.getKey():xx[1];
            }else if (entry.getValue() == 4){
                xx[0] = "5";
                xx[1] = entry.getKey().compareTo(xx[1]) > 0 ? entry.getKey():xx[1];
            }
        }
        if ("5".equals(xx[0])){
            return xx;
        }
        boolean sz = true;
        for (int i = 1; i < s.length; i++) {
            if (ll.get(s[i]) - ll.get(s[i-1]) != 1){
                sz = false;
                break;
            }
        }
        if (!sz){
            return xx;
        }
        xx[0] = "4";
        xx[1] = s[0];
        return xx;
    }
    static Map<String, Integer> ll = new HashMap<>();
    static{
        ll.put("3",3);
        ll.put("4",4);
        ll.put("5",5);
        ll.put("6",6);
        ll.put("7",7);
        ll.put("8",8);
        ll.put("9",9);
        ll.put("10",10);
        ll.put("J",11);
        ll.put("Q",12);
        ll.put("K",13);
        ll.put("A",14);
        ll.put("2",15);
        ll.put("joker",16);
        ll.put("JOKER",17);
    }
}
